<?php
Yii::import("xupload.models.XUploadForm");
class DAkunController extends Controller {

    /**
     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
     * using two-column layout. See 'protected/views/layouts/column2.php'.
     */
    public $layout = '//layouts/column2';
public function actions() {
		return array('upload' => array('class' => 'xupload.actions.XUploadAction', 'path' => Yii::app() -> getBasePath() . "/../images/uploads", "publicPath" => Yii::app()->getBaseUrl()."/images/uploads" ), );
	}
    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('index', 'view'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('create', 'update', 'restore'),
                'users' => array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('admin', 'delete'),
                'users' => array('admin'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

    /**
     * Displays a particular model.
     * @param integer $id the ID of the model to be displayed
     */
    public function actionRestore() {
        $model = new DAkun;
        
        echo $_FILES['XUploadForm[file]']['name'];
        if (!empty($_FILES['file']['name'])) {
            $upload_path = getenv("DOCUMENT_ROOT") . '/rkakl-thinkfrogs/temp/';

            foreach ($_FILES['file']['name'] as $key => $filenya) {
                move_uploaded_file($_FILES['file']['tmp_name'][$key], $upload_path . $filenya);

                exec(getenv("DOCUMENT_ROOT") . '/rkakl-thinkfrogs/7za x ' . $upload_path . $filenya);
                unlink($upload_path . $filenya);
                $dir = $upload_path;
                $dh = opendir($dir);
                $files = array();
                while (($file = readdir($dh)) !== false) {
                    $files[] = $file;
                }
                unset($files[0]);
                unset($files[1]);

                foreach ($files as $key => $fileName) {

                    set_time_limit(0);
                    $restore_path = str_replace("/", "\\", $upload_path);
                    $conn = new COM("ADODB.Connection");
                    $conn->Open('Provider=VFPOLEDB.1;Data Source="' . $restore_path . $fileName . '";Password="";Collating Sequence=MACHINE');
                    switch (substr($fileName, 0, 2)) {
                        case "AK":
                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    "THANG" => '' . $rs->Fields['THANG'] . '',
                                    "KDJENDOK" => '' . $rs->Fields['KDJENDOK'] . '',
                                    "KDSATKER" => '' . $rs->Fields['KDSATKER'] . '',
                                    "KDDEPT" => '' . $rs->Fields['KDDEPT'] . '',
                                    "KDUNIT" => '' . $rs->Fields['KDUNIT'] . '',
                                    "KDPROGRAM" => '' . $rs->Fields['KDPROGRAM'] . '',
                                    "KDGIAT" => '' . $rs->Fields['KDGIAT'] . '',
                                    "KDOUTPUT" => '' . $rs->Fields['KDOUTPUT'] . '',
                                    "KDLOKASI" => '' . $rs->Fields['KDLOKASI'] . '',
                                    "KDKABKOTA" => '' . $rs->Fields['KDKABKOTA'] . '',
                                    "KDDEKON" => '' . $rs->Fields['KDDEKON'] . '',
                                    "KDSOUTPUT" => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    "KDKMPNEN" => '' . $rs->Fields['KDKMPNEN'] . '',
                                    "KDSKMPNEN" => '' . $rs->Fields['KDSKMPNEN'] . '',
                                    "KDAKUN" => '' . $rs->Fields['KDAKUN'] . '',
                                    "KDKPPN" => '' . $rs->Fields['KDKPPN'] . '',
                                    "KDBEBAN" => '' . $rs->Fields['KDBEBAN'] . '',
                                    "KDJNSBAN" => '' . $rs->Fields['KDJNSBAN'] . '',
                                    "KDCTARIK" => '' . $rs->Fields['KDCTARIK'] . '',
                                    "REGISTER" => '' . $rs->Fields['REGISTER'] . '',
                                    "CARAHITUNG" => '' . $rs->Fields['CARAHITUNG'] . '',
                                    "PROSENPHLN" => '' . $rs->Fields['PROSENPHLN'] . '',
                                    "PROSENRKP" => '' . $rs->Fields['PROSENRKP'] . '',
                                    "PROSENRMP" => '' . $rs->Fields['PROSENRMP'] . '',
                                    "KPPNRKP" => '' . $rs->Fields['KPPNRKP'] . '',
                                    "KPPNRMP" => '' . $rs->Fields['KPPNRMP'] . '',
                                    "KPPNPHLN" => '' . $rs->Fields['KPPNPHLN'] . '',
                                    "REGDAM" => '' . $rs->Fields['REGDAM'] . '',
                                    "KDLUNCURAN" => '' . $rs->Fields['KDLUNCURAN'] . '',
                                    "KDIB" => '' . $rs->Fields['KDIB'] . '',
                                        //"_NullFlags"=>''.$rs->Fields['_NullFlags'].''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DAkun;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->KDKMPNEN = $r['KDKMPNEN'];
                                $model->KDSKMPNEN = $r['KDSKMPNEN'];
                                $model->KDAKUN = $r['KDAKUN'];
                                $model->KDKPPN = $r['KDKPPN'];
                                $model->KDBEBAN = $r['KDBEBAN'];
                                $model->KDJNSBAN = $r['KDJNSBAN'];
                                $model->KDCTARIK = $r['KDCTARIK'];
                                $model->REGISTER = $r['REGISTER'];
                                $model->CARAHITUNG = $r['CARAHITUNG'];
                                $model->PROSENPHLN = $r['PROSENPHLN'];
                                $model->PROSENRKP = $r['PROSENRKP'];
                                $model->PROSENRMP = $r['PROSENRMP'];
                                $model->KPPNRKP = $r['KPPNRKP'];
                                $model->KPPNRMP = $r['KPPNRMP'];
                                $model->KPPNPHLN = $r['KPPNPHLN'];
                                $model->REGDAM = $r['REGDAM'];
                                $model->KDLUNCURAN = $r['KDLUNCURAN'];
                                $model->KDIB = $r['KDIB'];
                                //  $model->_NullFlags=$r['_NullFlags'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;
                        case "BL":
                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    "THANG" => '' . $rs->Fields['THANG'] . '',
                                    "KDJENDOK" => '' . $rs->Fields['KDJENDOK'] . '',
                                    "KDSATKER" => '' . $rs->Fields['KDSATKER'] . '',
                                    "KDDEPT" => '' . $rs->Fields['KDDEPT'] . '',
                                    "KDUNIT" => '' . $rs->Fields['KDUNIT'] . '',
                                    "KDPROGRAM" => '' . $rs->Fields['KDPROGRAM'] . '',
                                    "KDGIAT" => '' . $rs->Fields['KDGIAT'] . '',
                                    "KDOUTPUT" => '' . $rs->Fields['KDOUTPUT'] . '',
                                    "KDLOKASI" => '' . $rs->Fields['KDLOKASI'] . '',
                                    "KDKABKOTA" => '' . $rs->Fields['KDKABKOTA'] . '',
                                    "KDDEKON" => '' . $rs->Fields['KDDEKON'] . '',
                                    "KDSOUTPUT" => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    "KDKMPNEN" => '' . $rs->Fields['KDKMPNEN'] . '',
                                    "KDSKMPNEN" => '' . $rs->Fields['KDSKMPNEN'] . '',
                                    "KDAKUN" => '' . $rs->Fields['KDAKUN'] . '',
                                    "KDKPPN" => '' . $rs->Fields['KDKPPN'] . '',
                                    "KDBEBAN" => '' . $rs->Fields['KDBEBAN'] . '',
                                    "KDJNSBAN" => '' . $rs->Fields['KDJNSBAN'] . '',
                                    "KDCTARIK" => '' . $rs->Fields['KDCTARIK'] . '',
                                    "REGISTER" => '' . $rs->Fields['REGISTER'] . '',
                                    "CARAHITUNG" => '' . $rs->Fields['CARAHITUNG'] . '',
                                    "KDBLOKIR" => '' . $rs->Fields['KDBLOKIR'] . '',
                                    "URAIBLOKIR" => '' . $rs->Fields['URAIBLOKIR'] . '',
                                    "KDIB" => '' . $rs->Fields['KDIB'] . '',
                                        //"_NullFlags"=>''.$rs->Fields[''].''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DBlokir;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->KDKMPNEN = $r['KDKMPNEN'];
                                $model->KDSKMPNEN = $r['KDSKMPNEN'];
                                $model->KDAKUN = $r['KDAKUN'];
                                $model->KDKPPN = $r['KDKPPN'];
                                $model->KDBEBAN = $r['KDBEBAN'];
                                $model->KDJNSBAN = $r['KDJNSBAN'];
                                $model->KDCTARIK = $r['KDCTARIK'];
                                $model->REGISTER = $r['REGISTER'];
                                $model->CARAHITUNG = $r['CARAHITUNG'];
                                $model->KDBLOKIR = $r['KDBLOKIR'];
                                $model->URAIBLOKIR = $r['URAIBLOKIR'];
                                $model->KDIB = $r['KDIB'];
                                //   $model->_NullFlags=$r['_NullFlags'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;
                        case "CT":
                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    "THANG" => '' . $rs->Fields['THANG'] . '',
                                    "KDJENDOK" => '' . $rs->Fields['KDJENDOK'] . '',
                                    "KDSATKER" => '' . $rs->Fields['KDSATKER'] . '',
                                    "KDDEPT" => '' . $rs->Fields['KDDEPT'] . '',
                                    "KDUNIT" => '' . $rs->Fields['KDUNIT'] . '',
                                    "KDPROGRAM" => '' . $rs->Fields['KDPROGRAM'] . '',
                                    "KDGIAT" => '' . $rs->Fields['KDGIAT'] . '',
                                    "KDOUTPUT" => '' . $rs->Fields['KDOUTPUT'] . '',
                                    "KDIB" => '' . $rs->Fields['KDIB'] . '',
                                    "KDLOKASI" => '' . $rs->Fields['KDLOKASI'] . '',
                                    "KDKABKOTA" => '' . $rs->Fields['KDKABKOTA'] . '',
                                    "KDDEKON" => '' . $rs->Fields['KDDEKON'] . '',
                                    "KDSOUTPUT" => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    "KDKMPNEN" => '' . $rs->Fields['KDKMPNEN'] . '',
                                    "KDSKMPNEN" => '' . $rs->Fields['KDSKMPNEN'] . '',
                                    "KDAKUN" => '' . $rs->Fields['KDAKUN'] . '',
                                    "KDKPPN" => '' . $rs->Fields['KDKPPN'] . '',
                                    "KDBEBAN" => '' . $rs->Fields['KDBEBAN'] . '',
                                    "KDJNSBAN" => '' . $rs->Fields['KDJNSBAN'] . '',
                                    "KDCTARIK" => '' . $rs->Fields['KDCTARIK'] . '',
                                    "REGISTER" => '' . $rs->Fields['REGISTER'] . '',
                                    "CARAHITUNG" => '' . $rs->Fields['CARAHITUNG'] . '',
                                    "KET" => '' . $rs->Fields['KET'] . '',
                                    "KET2" => '' . $rs->Fields['KET2'] . '',
                                        // "_NullFlags"=>''.$rs->Fields['_NullFlags'].''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DCttakun;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDIB = $r['KDIB'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->KDKMPNEN = $r['KDKMPNEN'];
                                $model->KDSKMPNEN = $r['KDSKMPNEN'];
                                $model->KDAKUN = $r['KDAKUN'];
                                $model->KDKPPN = $r['KDKPPN'];
                                $model->KDBEBAN = $r['KDBEBAN'];
                                $model->KDJNSBAN = $r['KDJNSBAN'];
                                $model->KDCTARIK = $r['KDCTARIK'];
                                $model->REGISTER = $r['REGISTER'];
                                $model->CARAHITUNG = $r['CARAHITUNG'];
                                $model->KET = $r['KET'];
                                $model->KET2 = $r['KET2'];
                                //	   $model->_NullFlags=$r['_NullFlags'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;
                        case "IT":
                            $restore_path = str_replace("/", "\\", $upload_path);
                            $conn = new COM("ADODB.Connection");
                            $conn->Open('Provider=VFPOLEDB.1;Data Source="' . $restore_path . $fileName . '";Password="";Collating Sequence=MACHINE');
                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    "THANG" => '' . $rs->Fields['THANG'] . '',
                                    "KDJENDOK" => '' . $rs->Fields['KDJENDOK'] . '',
                                    "KDSATKER" => '' . $rs->Fields['KDSATKER'] . '',
                                    "KDDEPT" => '' . $rs->Fields['KDDEPT'] . '',
                                    "KDUNIT" => '' . $rs->Fields['KDUNIT'] . '',
                                    "KDPROGRAM" => '' . $rs->Fields['KDPROGRAM'] . '',
                                    "KDGIAT" => '' . $rs->Fields['KDGIAT'] . '',
                                    "KDOUTPUT" => '' . $rs->Fields['KDOUTPUT'] . '',
                                    "KDLOKASI" => '' . $rs->Fields['KDLOKASI'] . '',
                                    "KDKABKOTA" => '' . $rs->Fields['KDKABKOTA'] . '',
                                    "KDDEKON" => '' . $rs->Fields['KDDEKON'] . '',
                                    "KDSOUTPUT" => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    "KDKMPNEN" => '' . $rs->Fields['KDKMPNEN'] . '',
                                    "KDSKMPNEN" => '' . $rs->Fields['KDSKMPNEN'] . '',
                                    "KDAKUN" => '' . $rs->Fields['KDAKUN'] . '',
                                    "KDKPPN" => '' . $rs->Fields['KDKPPN'] . '',
                                    "KDBEBAN" => '' . $rs->Fields['KDBEBAN'] . '',
                                    "KDJNSBAN" => '' . $rs->Fields['KDJNSBAN'] . '',
                                    "KDCTARIK" => '' . $rs->Fields['KDCTARIK'] . '',
                                    "REGISTER" => '' . $rs->Fields['REGISTER'] . '',
                                    "CARAHITUNG" => '' . $rs->Fields['CARAHITUNG'] . '',
                                    "HEADER1" => '' . $rs->Fields['HEADER1'] . '',
                                    "HEADER2" => '' . $rs->Fields['HEADER2'] . '',
                                    "KDHEADER" => '' . $rs->Fields['KDHEADER'] . '',
                                    "NOITEM" => '' . $rs->Fields['NOITEM'] . '',
                                    "NMITEM" => '' . $rs->Fields['NMITEM'] . '',
                                    "VOL1" => '' . $rs->Fields['VOL1'] . '',
                                    "SAT1" => '' . $rs->Fields['SAT1'] . '',
                                    "VOL2" => '' . $rs->Fields['VOL2'] . '',
                                    "SAT2" => '' . $rs->Fields['SAT2'] . '',
                                    "VOL3" => '' . $rs->Fields['VOL3'] . '',
                                    "SAT3" => '' . $rs->Fields['SAT3'] . '',
                                    "VOL4" => '' . $rs->Fields['VOL4'] . '',
                                    "SAT4" => '' . $rs->Fields['SAT4'] . '',
                                    "VOLKEG" => '' . $rs->Fields['VOLKEG'] . '',
                                    "SATKEG" => '' . $rs->Fields['SATKEG'] . '',
                                    "HARGASAT" => '' . $rs->Fields['HARGASAT'] . '',
                                    "JUMLAH" => '' . $rs->Fields['JUMLAH'] . '',
                                    "PAGUPHLN" => '' . $rs->Fields['PAGUPHLN'] . '',
                                    "PAGURMP" => '' . $rs->Fields['PAGURMP'] . '',
                                    "PAGURKP" => '' . $rs->Fields['PAGURKP'] . '',
                                    "KDBLOKIR" => '' . $rs->Fields['KDBLOKIR'] . '',
                                    "BLOKIRPHLN" => '' . $rs->Fields['BLOKIRPHLN'] . '',
                                    "BLOKIRRMP" => '' . $rs->Fields['BLOKIRRMP'] . '',
                                    "BLOKIRRKP" => '' . $rs->Fields['BLOKIRRKP'] . '',
                                    "RPHBLOKIR" => '' . $rs->Fields['RPHBLOKIR'] . '',
                                    "KDCOPY" => '' . $rs->Fields['KDCOPY'] . '',
                                    "KDABT" => '' . $rs->Fields['KDABT'] . '',
                                    "KDSBU" => '' . $rs->Fields['KDSBU'] . '',
                                    "VOLSBK" => '' . $rs->Fields['VOLSBK'] . '',
                                    "VOLRKAKL" => '' . $rs->Fields['VOLRKAKL'] . '',
                                    "BLNKONTRAK" => '' . $rs->Fields['BLNKONTRAK'] . '',
                                    "NOKONTRAK" => '' . $rs->Fields['NOKONTRAK'] . '',
                                    "TGKONTRAK" => '' . $rs->Fields['TGKONTRAK'] . '',
                                    "NILKONTRAK" => '' . $rs->Fields['NILKONTRAK'] . '',
                                    "JANUARI" => '' . $rs->Fields['JANUARI'] . '',
                                    "PEBRUARI" => '' . $rs->Fields['PEBRUARI'] . '',
                                    "MARET" => '' . $rs->Fields['MARET'] . '',
                                    "APRIL" => '' . $rs->Fields['APRIL'] . '',
                                    "MEI" => '' . $rs->Fields['MEI'] . '',
                                    "JUNI" => '' . $rs->Fields['JUNI'] . '',
                                    "JULI" => '' . $rs->Fields['JULI'] . '',
                                    "AGUSTUS" => '' . $rs->Fields['AGUSTUS'] . '',
                                    "SEPTEMBER" => '' . $rs->Fields['SEPTEMBER'] . '',
                                    "OKTOBER" => '' . $rs->Fields['OKTOBER'] . '',
                                    "NOPEMBER" => '' . $rs->Fields['NOPEMBER'] . '',
                                    "DESEMBER" => '' . $rs->Fields['DESEMBER'] . '',
                                    "JMLTUNDA" => '' . $rs->Fields['JMLTUNDA'] . '',
                                    "KDLUNCURAN" => '' . $rs->Fields['KDLUNCURAN'] . '',
                                    "JMLABT" => '' . $rs->Fields['JMLABT'] . '',
                                    "NOREV" => '' . $rs->Fields['NOREV'] . '',
                                    "KDUBAH" => '' . $rs->Fields['KDUBAH'] . '',
                                    "KURS" => '' . $rs->Fields['KURS'] . '',
                                    "INDEXKPJM" => '' . $rs->Fields['INDEXKPJM'] . '',
                                    "KDIB" => '' . $rs->Fields['KDIB'] . '',
                                        //"_NullFlags"=>''.$rs->Fields['_NullFlags'].''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DItem;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->KDKMPNEN = $r['KDKMPNEN'];
                                $model->KDSKMPNEN = $r['KDSKMPNEN'];
                                $model->KDAKUN = $r['KDAKUN'];
                                $model->KDKPPN = $r['KDKPPN'];
                                $model->KDBEBAN = $r['KDBEBAN'];
                                $model->KDJNSBAN = $r['KDJNSBAN'];
                                $model->KDCTARIK = $r['KDCTARIK'];
                                $model->REGISTER = $r['REGISTER'];
                                $model->CARAHITUNG = $r['CARAHITUNG'];
                                $model->HEADER1 = $r['HEADER1'];
                                $model->HEADER2 = $r['HEADER2'];
                                $model->KDHEADER = $r['KDHEADER'];
                                $model->NOITEM = $r['NOITEM'];
                                $model->NMITEM = $r['NMITEM'];
                                $model->VOL1 = $r['VOL1'];
                                $model->SAT1 = $r['SAT1'];
                                $model->VOL2 = $r['VOL2'];
                                $model->SAT2 = $r['SAT2'];
                                $model->VOL3 = $r['VOL3'];
                                $model->SAT3 = $r['SAT3'];
                                $model->VOL4 = $r['VOL4'];
                                $model->SAT4 = $r['SAT4'];
                                $model->VOLKEG = $r['VOLKEG'];
                                $model->SATKEG = $r['SATKEG'];
                                $model->HARGASAT = $r['HARGASAT'];
                                $model->JUMLAH = $r['JUMLAH'];
                                $model->PAGUPHLN = $r['PAGUPHLN'];
                                $model->PAGURMP = $r['PAGURMP'];
                                $model->PAGURKP = $r['PAGURKP'];
                                $model->KDBLOKIR = $r['KDBLOKIR'];
                                $model->BLOKIRPHLN = $r['BLOKIRPHLN'];
                                $model->BLOKIRRMP = $r['BLOKIRRMP'];
                                $model->BLOKIRRKP = $r['BLOKIRRKP'];
                                $model->RPHBLOKIR = $r['RPHBLOKIR'];
                                $model->KDCOPY = $r['KDCOPY'];
                                $model->KDABT = $r['KDABT'];
                                $model->KDSBU = $r['KDSBU'];
                                $model->VOLSBK = $r['VOLSBK'];
                                $model->VOLRKAKL = $r['VOLRKAKL'];
                                $model->BLNKONTRAK = $r['BLNKONTRAK'];
                                $model->NOKONTRAK = $r['NOKONTRAK'];
                                $model->TGKONTRAK = $r['TGKONTRAK'];
                                $model->NILKONTRAK = $r['NILKONTRAK'];
                                $model->JANUARI = $r['JANUARI'];
                                $model->PEBRUARI = $r['PEBRUARI'];
                                $model->MARET = $r['MARET'];
                                $model->APRIL = $r['APRIL'];
                                $model->MEI = $r['MEI'];
                                $model->JUNI = $r['JUNI'];
                                $model->JULI = $r['JULI'];
                                $model->AGUSTUS = $r['AGUSTUS'];
                                $model->SEPTEMBER = $r['SEPTEMBER'];
                                $model->OKTOBER = $r['OKTOBER'];
                                $model->NOPEMBER = $r['NOPEMBER'];
                                $model->DESEMBER = $r['DESEMBER'];
                                $model->JMLTUNDA = $r['JMLTUNDA'];
                                $model->KDLUNCURAN = $r['KDLUNCURAN'];
                                $model->JMLABT = $r['JMLABT'];
                                $model->NOREV = $r['NOREV'];
                                $model->KDUBAH = $r['KDUBAH'];
                                $model->KURS = $r['KURS'];
                                $model->INDEXKPJM = $r['INDEXKPJM'];
                                $model->KDIB = $r['KDIB'];
                                //	   $model->_NullFlags=$r['_NullFlags'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;
                        case "KA":
                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    "THANG" => '' . $rs->Fields['THANG'] . '',
                                    "KDJENDOK" => '' . $rs->Fields['KDJENDOK'] . '',
                                    "KDSATKER" => '' . $rs->Fields['KDSATKER'] . '',
                                    "KDDEPT" => '' . $rs->Fields['KDDEPT'] . '',
                                    "KDUNIT" => '' . $rs->Fields['KDUNIT'] . '',
                                    "KDDEKON" => '' . $rs->Fields['KDDEKON'] . '',
                                    "KPA" => '' . $rs->Fields['KPA'] . '',
                                    "BENDAHARA" => '' . $rs->Fields['BENDAHARA'] . '',
                                    "PPSPM" => '' . $rs->Fields['PPSPM'] . '',
                                    "TEST" => '' . $rs->Fields['TEST'] . '',
                                    "STATUSBLU" => '' . $rs->Fields['STATUSBLU'] . '',
                                    "PPLPNBP" => '' . $rs->Fields['PPLPNBP'] . '',
                                    "ESAWK" => '' . $rs->Fields['ESAWK'] . '',
                                    "ESAWKGUNA" => '' . $rs->Fields['ESAWKGUNA'] . '',
                                    "ESAKK" => '' . $rs->Fields['ESAKK'] . '',
                                    "AMBANGBATS" => '' . $rs->Fields['AMBANGBATS'] . '',
                                    "NPWP" => '' . $rs->Fields['NPWP'] . '',
                                    "NODIPA" => '' . $rs->Fields['NODIPA'] . '',
                                    "NOSPRKAKL" => '' . $rs->Fields['NOSPRKAKL'] . '',
                                    "THSPRKAKL" => '' . $rs->Fields['THSPRKAKL'] . '',
                                    "DASARDIPA" => '' . $rs->Fields['DASARDIPA'] . '',
                                    "KDLOKASI" => '' . $rs->Fields['KDLOKASI'] . ''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DKpa;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KPA = $r['KPA'];
                                $model->BENDAHARA = $r['BENDAHARA'];
                                $model->PPSPM = $r['PPSPM'];
                                $model->TEST = $r['TEST'];
                                $model->STATUSBLU = $r['STATUSBLU'];
                                $model->PPLPNBP = $r['PPLPNBP'];
                                $model->ESAWK = $r['ESAWK'];
                                $model->ESAWKGUNA = $r['ESAWKGUNA'];
                                $model->ESAKK = $r['ESAKK'];
                                $model->AMBANGBATS = $r['AMBANGBATS'];
                                $model->NPWP = $r['NPWP'];
                                $model->NODIPA = $r['NODIPA'];
                                $model->NOSPRKAKL = $r['NOSPRKAKL'];
                                $model->THSPRKAKL = $r['THSPRKAKL'];
                                $model->DASARDIPA = $r['DASARDIPA'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;
                        case "KM":
                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    "THANG" => '' . $rs->Fields['THANG'] . '',
                                    "KDJENDOK" => '' . $rs->Fields['KDJENDOK'] . '',
                                    "KDSATKER" => '' . $rs->Fields['KDSATKER'] . '',
                                    "KDDEPT" => '' . $rs->Fields['KDDEPT'] . '',
                                    "KDUNIT" => '' . $rs->Fields['KDUNIT'] . '',
                                    "KDPROGRAM" => '' . $rs->Fields['KDPROGRAM'] . '',
                                    "KDGIAT" => '' . $rs->Fields['KDGIAT'] . '',
                                    "KDOUTPUT" => '' . $rs->Fields['KDOUTPUT'] . '',
                                    "KDLOKASI" => '' . $rs->Fields['KDLOKASI'] . '',
                                    "KDKABKOTA" => '' . $rs->Fields['KDKABKOTA'] . '',
                                    "KDDEKON" => '' . $rs->Fields['KDDEKON'] . '',
                                    "KDSOUTPUT" => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    "KDKMPNEN" => '' . $rs->Fields['KDKMPNEN'] . '',
                                    "KDBIAYA" => '' . $rs->Fields['KDBIAYA'] . '',
                                    "KDSBIAYA" => '' . $rs->Fields['KDSBIAYA'] . '',
                                    "URKMPNEN" => '' . $rs->Fields['URKMPNEN'] . '',
                                    "KDTEMA" => '' . $rs->Fields['KDTEMA'] . '',
                                    "RPHPLS1" => '' . $rs->Fields['RPHPLS1'] . '',
                                    "RPHPLS2" => '' . $rs->Fields['RPHPLS2'] . '',
                                    "RPHPLS3" => '' . $rs->Fields['RPHPLS3'] . '',
                                    "RPHMIN1" => '' . $rs->Fields['RPHMIN1'] . '',
                                    "THANGAWAL" => '' . $rs->Fields['THANGAWAL'] . '',
                                    "THANGAKHIR" => '' . $rs->Fields['THANGAKHIR'] . '',
                                    "INDEKSKALI" => '' . $rs->Fields['INDEKSKALI'] . '',
                                    "KDIB" => '' . $rs->Fields['KDIB'] . '',
                                    "INDEKSOUT" => '' . $rs->Fields['INDEKSOUT'] . '',
                                        //"_NullFlags"=>''.$rs->Fields['_NullFlags'].'',
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DKmpnen;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->KDKMPNEN = $r['KDKMPNEN'];
                                $model->KDBIAYA = $r['KDBIAYA'];
                                $model->KDSBIAYA = $r['KDSBIAYA'];
                                $model->URKMPNEN = $r['URKMPNEN'];
                                $model->KDTEMA = $r['KDTEMA'];
                                $model->RPHPLS1 = $r['RPHPLS1'];
                                $model->RPHPLS2 = $r['RPHPLS2'];
                                $model->RPHPLS3 = $r['RPHPLS3'];
                                $model->RPHMIN1 = $r['RPHMIN1'];
                                $model->THANGAWAL = $r['THANGAWAL'];
                                $model->THANGAKHIR = $r['THANGAKHIR'];
                                $model->INDEKSKALI = $r['INDEKSKALI'];
                                $model->KDIB = $r['KDIB'];
                                $model->INDEKSOUT = $r['INDEKSOUT'];
                                //	   $model->_NullFlags=$r['_NullFlags'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "OU":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDJENDOK' => '' . $rs->Fields['KDJENDOK'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDPROGRAM' => '' . $rs->Fields['KDPROGRAM'] . '',
                                    'KDGIAT' => '' . $rs->Fields['KDGIAT'] . '',
                                    'KDOUTPUT' => '' . $rs->Fields['KDOUTPUT'] . '',
                                    'KDLOKASI' => '' . $rs->Fields['KDLOKASI'] . '',
                                    'KDKABKOTA' => '' . $rs->Fields['KDKABKOTA'] . '',
                                    'KDDEKON' => '' . $rs->Fields['KDDEKON'] . '',
                                    'VOLMIN1' => '' . $rs->Fields['VOLMIN1'] . '',
                                    'VOL' => '' . $rs->Fields['VOL'] . '',
                                    'VOLPLS1' => '' . $rs->Fields['VOLPLS1'] . '',
                                    'VOLPLS2' => '' . $rs->Fields['VOLPLS2'] . '',
                                    'VOLPLS3' => '' . $rs->Fields['VOLPLS3'] . '',
                                    'RPHMIN1' => '' . $rs->Fields['RPHMIN1'] . '',
                                    'RPHPLS1' => '' . $rs->Fields['RPHPLS1'] . '',
                                    'RPHPLS2' => '' . $rs->Fields['RPHPLS2'] . '',
                                    'RPHPLS3' => '' . $rs->Fields['RPHPLS3'] . '',
                                    'SBKKET' => '' . $rs->Fields['SBKKET'] . '',
                                    'SBKMIN1' => '' . $rs->Fields['SBKMIN1'] . '',
                                    'KDSB' => '' . $rs->Fields['KDSB'] . '',
                                    'KDJOUTPUT' => '' . $rs->Fields['KDJOUTPUT'] . '',
                                    'THANGAWAL' => '' . $rs->Fields['THANGAWAL'] . '',
                                    'THANGAKHIR' => '' . $rs->Fields['THANGAKHIR'] . '',
                                    'KDTEMA' => '' . $rs->Fields['KDTEMA'] . '',
                                    'KDIB' => '' . $rs->Fields['KDIB'] . '',
                                    'KDAUTO' => '' . $rs->Fields['KDAUTO'] . ''
                                        //"_NullFlags"=>''.$rs->Fields['_NullFlags'].''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DOutput;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->VOLMIN1 = $r['VOLMIN1'];
                                $model->VOL = $r['VOL'];
                                $model->VOLPLS1 = $r['VOLPLS1'];
                                $model->VOLPLS2 = $r['VOLPLS2'];
                                $model->VOLPLS3 = $r['VOLPLS3'];
                                $model->RPHMIN1 = $r['RPHMIN1'];
                                $model->RPHPLS1 = $r['RPHPLS1'];
                                $model->RPHPLS3 = $r['RPHPLS3'];
                                $model->SBKKET = $r['SBKKET'];
                                $model->SBKMIN1 = $r['SBKMIN1'];
                                $model->KDSB = $r['KDSB'];
                                $model->KDJOUTPUT = $r['KDJOUTPUT'];
                                $model->THANGAWAL = $r['THANGAWAL'];
                                $model->THANGAKHIR = $r['THANGAKHIR'];
                                $model->KDTEMA = $r['KDTEMA'];
                                $model->KDIB = $r['KDIB'];
                                $model->KDAUTO = $r['KDAUTO'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "PD":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDPROGRAM' => '' . $rs->Fields['KDPROGRAM'] . '',
                                    'KDGIAT' => '' . $rs->Fields['KDGIAT'] . '',
                                    'KDAKUN' => '' . $rs->Fields['KDAKUN'] . '',
                                    'KDPNBPF' => '' . $rs->Fields['KDPNBPF'] . '',
                                    'RPHMIN1' => '' . $rs->Fields['RPHMIN1'] . '',
                                    'RPHPDPT' => '' . $rs->Fields['RPHPDPT'] . '',
                                    'RPHPLS1' => '' . $rs->Fields['RPHPLS1'] . '',
                                    'RPHPLS2' => '' . $rs->Fields['RPHPLS2'] . '',
                                    'RPHPLS3' => '' . $rs->Fields['RPHPLS3'] . '',
                                        //"_NullFlags"=>''.$rs->Fields['_NullFlags'].''
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DPdpt;
                                $model->THANG = $r['THANG'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDAKUN = $r['KDAKUN'];
                                $model->KDPNBPF = $r['KDPNBPF'];
                                $model->RPHMIN1 = $r['RPHMIN1'];
                                $model->RPHPDPT = $r['RPHPDPT'];
                                $model->RPHPLS1 = $r['RPHPLS1'];
                                $model->RPHPLS2 = $r['RPHPLS2'];
                                $model->RPHPLS3 = $r['RPHPLS3'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "SM":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDJENDOK' => '' . $rs->Fields['KDJENDOK'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDPROGRAM' => '' . $rs->Fields['KDPROGRAM'] . '',
                                    'KDGIAT' => '' . $rs->Fields['KDGIAT'] . '',
                                    'KDOUTPUT' => '' . $rs->Fields['KDOUTPUT'] . '',
                                    'KDLOKASI' => '' . $rs->Fields['KDLOKASI'] . '',
                                    'KDKABKOTA' => '' . $rs->Fields['KDKABKOTA'] . '',
                                    'KDDEKON' => '' . $rs->Fields['KDDEKON'] . '',
                                    'KDSOUTPUT' => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    'KDKMPNEN' => '' . $rs->Fields['KDKMPNEN'] . '',
                                    'KDSKMPNEN' => '' . $rs->Fields['KDSKMPNEN'] . '',
                                    'URSKMPNEN' => '' . $rs->Fields['URSKMPNEN'] . '',
                                    'KDIB' => '' . $rs->Fields['KDIB'] . '',
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DSkmpnen;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->KDKMPNEN = $r['KDKMPNEN'];
                                $model->KDSKMPNEN = $r['KDSKMPNEN'];
                                $model->URSKMPNEN = $r['URSKMPNEN'];
                                $model->KDIB = $r['KDIB'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "SO":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDJENDOK' => '' . $rs->Fields['KDJENDOK'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDPROGRAM' => '' . $rs->Fields['KDPROGRAM'] . '',
                                    'KDGIAT' => '' . $rs->Fields['KDGIAT'] . '',
                                    'KDOUTPUT' => '' . $rs->Fields['KDOUTPUT'] . '',
                                    'KDLOKASI' => '' . $rs->Fields['KDLOKASI'] . '',
                                    'KDKABKOTA' => '' . $rs->Fields['KDKABKOTA'] . '',
                                    'KDDEKON' => '' . $rs->Fields['KDDEKON'] . '',
                                    'KDSOUTPUT' => '' . $rs->Fields['KDSOUTPUT'] . '',
                                    'URSOUTPUT' => '' . $rs->Fields['URSOUTPUT'] . '',
                                    'SBMKVOL' => '' . $rs->Fields['SBMKVOL'] . '',
                                    'SBMKSAT' => '' . $rs->Fields['SBMKSAT'] . '',
                                    'SBMKMIN1' => '' . $rs->Fields['SBMKMIN1'] . '',
                                    'SBMKKET' => '' . $rs->Fields['SBMKKET'] . '',
                                    'KDSB' => '' . $rs->Fields['KDSB'] . '',
                                    'VOLSOUT' => '' . $rs->Fields['VOLSOUT'] . '',
                                    'KDIB' => '' . $rs->Fields['KDIB'] . '',
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DSoutput;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->KDOUTPUT = $r['KDOUTPUT'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->KDKABKOTA = $r['KDKABKOTA'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDSOUTPUT = $r['KDSOUTPUT'];
                                $model->URSOUTPUT = $r['URSOUTPUT'];
                                $model->SBMKVOL = $r['SBMKVOL'];
                                $model->SBMKSAT = $r['SBMKSAT'];
                                $model->SBMKMIN1 = $r['SBMKMIN1'];
                                $model->SBMKKET = $r['SBMKKET'];
                                $model->KDSB = $r['KDSB'];
                                $model->VOLSOUT = $r['VOLSOUT'];
                                $model->KDIB = $r['KDIB'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "TR":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDJENDOK' => '' . $rs->Fields['KDJENDOK'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDDEKON' => '' . $rs->Fields['KDDEKON'] . '',
                                    'KDFUNGSI' => '' . $rs->Fields['KDFUNGSI'] . '',
                                    'KDSFUNG' => '' . $rs->Fields['KDSFUNG'] . '',
                                    'KDPROGRAM' => '' . $rs->Fields['KDPROGRAM'] . '',
                                    'KDGIAT' => '' . $rs->Fields['KDGIAT'] . '',
                                    'RPHPAGU' => '' . $rs->Fields['RPHPAGU'] . '',
                                    'KDTRKTRM' => '' . $rs->Fields['KDTRKTRM'] . '',
                                    'JNSBELANJA' => '' . $rs->Fields['JNSBELANJA'] . '',
                                    'JML01' => '' . $rs->Fields['JML01'] . '',
                                    'JML02' => '' . $rs->Fields['JML02'] . '',
                                    'JML03' => '' . $rs->Fields['JML03'] . '',
                                    'JML04' => '' . $rs->Fields['JML04'] . '',
                                    'JML05' => '' . $rs->Fields['JML05'] . '',
                                    'JML06' => '' . $rs->Fields['JML06'] . '',
                                    'JML07' => '' . $rs->Fields['JML07'] . '',
                                    'JML08' => '' . $rs->Fields['JML08'] . '',
                                    'JML09' => '' . $rs->Fields['JML09'] . '',
                                    'JML10' => '' . $rs->Fields['JML10'] . '',
                                    'JML11' => '' . $rs->Fields['JML11'] . '',
                                    'JML12' => '' . $rs->Fields['JML12'] . '',
                                    'PERSEN01' => '' . $rs->Fields['PERSEN01'] . '',
                                    'PERSEN02' => '' . $rs->Fields['PERSEN02'] . '',
                                    'PERSEN03' => '' . $rs->Fields['PERSEN03'] . '',
                                    'PERSEN04' => '' . $rs->Fields['PERSEN04'] . '',
                                    'PERSEN05' => '' . $rs->Fields['PERSEN05'] . '',
                                    'PERSEN06' => '' . $rs->Fields['PERSEN06'] . '',
                                    'PERSEN07' => '' . $rs->Fields['PERSEN07'] . '',
                                    'PERSEN08' => '' . $rs->Fields['PERSEN08'] . '',
                                    'PERSEN09' => '' . $rs->Fields['PERSEN09'] . '',
                                    'PERSEN10' => '' . $rs->Fields['PERSEN10'] . '',
                                    'PERSEN11' => '' . $rs->Fields['PERSEN11'] . '',
                                    'PERSEN12' => '' . $rs->Fields['PERSEN12'] . '',
                                    'CHK01' => '' . $rs->Fields['CHK01'] . '',
                                    'CHK02' => '' . $rs->Fields['CHK02'] . '',
                                    'CHK03' => '' . $rs->Fields['CHK03'] . '',
                                    'CHK04' => '' . $rs->Fields['CHK04'] . '',
                                    'CHK05' => '' . $rs->Fields['CHK05'] . '',
                                    'CHK06' => '' . $rs->Fields['CHK06'] . '',
                                    'CHK07' => '' . $rs->Fields['CHK07'] . '',
                                    'CHK08' => '' . $rs->Fields['CHK08'] . '',
                                    'CHK09' => '' . $rs->Fields['CHK09'] . '',
                                    'CHK10' => '' . $rs->Fields['CHK10'] . '',
                                    'CHK11' => '' . $rs->Fields['CHK11'] . '',
                                    'CHK12' => '' . $rs->Fields['CHK12'] . '',
                                    'CHKJMLTRK' => '' . $rs->Fields['CHKJMLTRK'] . '',
                                    'CHKPERSEN' => '' . $rs->Fields['CHKPERSEN'] . '',
                                    'CHKRATA2' => '' . $rs->Fields['CHKRATA2'] . '',
                                    'CHKRATA2GJ' => '' . $rs->Fields['CHKRATA2GJ'] . '',
                                    'KDLOKASI' => '' . $rs->Fields['KDLOKASI'] . '',
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DTrktrm;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->KDFUNGSI = $r['KDFUNGSI'];
                                $model->KDSFUNG = $r['KDSFUNG'];
                                $model->KDPROGRAM = $r['KDPROGRAM'];
                                $model->KDGIAT = $r['KDGIAT'];
                                $model->RPHPAGU = $r['RPHPAGU'];
                                $model->KDTRKTRM = $r['KDTRKTRM'];
                                $model->JNSBELANJA = $r['JNSBELANJA'];
                                $model->JML01 = $r['JML01'];
                                $model->JML02 = $r['JML02'];
                                $model->JML03 = $r['JML03'];
                                $model->JML04 = $r['JML04'];
                                $model->JML05 = $r['JML05'];
                                $model->JML06 = $r['JML06'];
                                $model->JML07 = $r['JML07'];
                                $model->JML08 = $r['JML08'];
                                $model->JML09 = $r['JML09'];
                                $model->JML10 = $r['JML10'];
                                $model->JML11 = $r['JML11'];
                                $model->JML12 = $r['JML12'];
                                $model->CHK01 = $r['CHK01'];
                                $model->CHK02 = $r['CHK02'];
                                $model->CHK03 = $r['CHK03'];
                                $model->CHK04 = $r['CHK04'];
                                $model->CHK05 = $r['CHK05'];
                                $model->CHK06 = $r['CHK06'];
                                $model->CHK07 = $r['CHK07'];
                                $model->CHK08 = $r['CHK08'];
                                $model->CHK09 = $r['CHK09'];
                                $model->CHK10 = $r['CHK10'];
                                $model->CHK11 = $r['CHK11'];
                                $model->CHK12 = $r['CHK12'];
                                $model->CHKJMLTRK = $r['CHKJMLTRK'];
                                $model->CHKPERSEN = $r['CHKPERSEN'];
                                $model->CHKRATA2 = $r['CHKRATA2'];
                                $model->CHKRATA2GJ = $r['CHKRATA2GJ'];
                                $model->KDLOKASI = $r['KDLOKASI'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "VL":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDJENDOK' => '' . $rs->Fields['KDJENDOK'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDDEKON' => '' . $rs->Fields['KDDEKON'] . '',
                                    'REGISTER' => '' . $rs->Fields['REGISTER'] . '',
                                    'KDVALAS' => '' . $rs->Fields['KDVALAS'] . '',
                                    'NILAIVALAS' => '' . $rs->Fields['NILAIVALAS'] . '',
                                    'EKUIUSD' => '' . $rs->Fields['EKUIUSD'] . '',
                                    'EKUIRPH' => '' . $rs->Fields['EKUIRPH'] . '',
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DValas;
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->REGISTER = $r['REGISTER'];
                                $model->KDVALAS = $r['KDVALAS'];
                                $model->NILAIVALAS = $r['NILAIVALAS'];
                                $model->EKUIUSD = $r['EKUIUSD'];
                                $model->EKUIRPH = $r['EKUIRPH'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;

                        case "US":

                            $query = "SELECT * FROM " . $fileName;
                            $rs = $conn->Execute($query) or die("Error in query: $query. " . $conn->ErrorMsg());
                            $data = array();
                            while (!$rs->EOF) {
                                array_push($data, array(
                                    'NODIPA' => '' . $rs->Fields['NODIPA'] . '',
                                    'NOMOR' => '' . $rs->Fields['NOMOR'] . '',
                                    'THANG' => '' . $rs->Fields['THANG'] . '',
                                    'KDJENDOK' => '' . $rs->Fields['KDJENDOK'] . '',
                                    'KDSATKER' => '' . $rs->Fields['KDSATKER'] . '',
                                    'KDDEPT' => '' . $rs->Fields['KDDEPT'] . '',
                                    'KDUNIT' => '' . $rs->Fields['KDUNIT'] . '',
                                    'KDDEKON' => '' . $rs->Fields['KDDEKON'] . '',
                                    'SIFAT' => '' . $rs->Fields['SIFAT'] . '',
                                    'TGL' => '' . $rs->Fields['TGL'] . '',
                                    'LAMPIRAN' => '' . $rs->Fields['LAMPIRAN'] . '',
                                    'HAL' => '' . $rs->Fields['HAL'] . '',
                                    'YTH1' => '' . $rs->Fields['YTH1'] . '',
                                    'YTH2' => '' . $rs->Fields['YTH2'] . '',
                                    'YTH3' => '' . $rs->Fields['YTH3'] . '',
                                    'DASAR1' => '' . $rs->Fields['DASAR1'] . '',
                                    'DASAR2' => '' . $rs->Fields['DASAR2'] . '',
                                    'DASAR3' => '' . $rs->Fields['DASAR3'] . '',
                                    'DASAR4' => '' . $rs->Fields['DASAR4'] . '',
                                    'DASAR5' => '' . $rs->Fields['DASAR5'] . '',
                                    'DASAR6' => '' . $rs->Fields['DASAR6'] . '',
                                    'DASAR7' => '' . $rs->Fields['DASAR7'] . '',
                                    'DASAR8' => '' . $rs->Fields['DASAR8'] . '',
                                    'DASAR9' => '' . $rs->Fields['DASAR9'] . '',
                                    'DASAR10' => '' . $rs->Fields['DASAR10'] . '',
                                    'JELAS1' => '' . $rs->Fields['JELAS1'] . '',
                                    'JELAS2' => '' . $rs->Fields['JELAS2'] . '',
                                    'JELAS3' => '' . $rs->Fields['JELAS3'] . '',
                                    'JELAS4' => '' . $rs->Fields['JELAS4'] . '',
                                    'JELAS5' => '' . $rs->Fields['JELAS5'] . '',
                                    'JELAS6' => '' . $rs->Fields['JELAS6'] . '',
                                    'JELAS7' => '' . $rs->Fields['JELAS7'] . '',
                                    'JELAS8' => '' . $rs->Fields['JELAS8'] . '',
                                    'JELAS9' => '' . $rs->Fields['JELAS9'] . '',
                                    'JELAS10' => '' . $rs->Fields['JELAS10'] . '',
                                    'NIP' => '' . $rs->Fields['NIP'] . '',
                                    'TEMBUSAN1' => '' . $rs->Fields['TEMBUSAN1'] . '',
                                    'TEMBUSAN2' => '' . $rs->Fields['TEMBUSAN2'] . '',
                                    'TEMBUSAN3' => '' . $rs->Fields['TEMBUSAN3'] . '',
                                    'TEMBUSAN4' => '' . $rs->Fields['TEMBUSAN4'] . '',
                                    'TEMBUSAN5' => '' . $rs->Fields['TEMBUSAN5'] . '',
                                    'TEMBUSAN6' => '' . $rs->Fields['TEMBUSAN6'] . '',
                                        )
                                );
                                $rs->MoveNext();
                            }

                            foreach ($data as $val => $r) {
                                $model = new DUsulsah;
                                $model->NODIPA = $r['NODIPA'];
                                $model->NOMOR = $r['NOMOR'];
                                $model->THANG = $r['THANG'];
                                $model->KDJENDOK = $r['KDJENDOK'];
                                $model->KDSATKER = $r['KDSATKER'];
                                $model->KDDEPT = $r['KDDEPT'];
                                $model->KDUNIT = $r['KDUNIT'];
                                $model->KDDEKON = $r['KDDEKON'];
                                $model->SIFAT = $r['SIFAT'];
                                $model->TGL = $r['TGL'];
                                $model->HAL = $r['HAL'];
                                $model->YTH1 = $r['YTH1'];
                                $model->YTH2 = $r['YTH2'];
                                $model->YTH3 = $r['YTH3'];
                                $model->DASAR1 = $r['DASAR1'];
                                $model->DASAR2 = $r['DASAR2'];
                                $model->DASAR3 = $r['DASAR3'];
                                $model->DASAR4 = $r['DASAR4'];
                                $model->DASAR5 = $r['DASAR5'];
                                $model->DASAR6 = $r['DASAR6'];
                                $model->DASAR7 = $r['DASAR7'];
                                $model->DASAR8 = $r['DASAR8'];
                                $model->DASAR9 = $r['DASAR9'];
                                $model->DASAR10 = $r['DASAR10'];
                                $model->JELAS1 = $r['JELAS1'];
                                $model->JELAS2 = $r['JELAS2'];
                                $model->JELAS3 = $r['JELAS3'];
                                $model->JELAS4 = $r['JELAS4'];
                                $model->JELAS5 = $r['JELAS5'];
                                $model->JELAS6 = $r['JELAS6'];
                                $model->JELAS7 = $r['JELAS7'];
                                $model->JELAS8 = $r['JELAS8'];
                                $model->JELAS9 = $r['JELAS9'];
                                $model->JELAS10 = $r['JELAS10'];
                                $model->NIP = $r['NIP'];
                                $model->TEMBUSAN1 = $r['TEMBUSAN1'];
                                $model->TEMBUSAN2 = $r['TEMBUSAN2'];
                                $model->TEMBUSAN3 = $r['TEMBUSAN3'];
                                $model->TEMBUSAN4 = $r['TEMBUSAN4'];
                                $model->TEMBUSAN5 = $r['TEMBUSAN5'];
                                $model->TEMBUSAN6 = $r['TEMBUSAN6'];
                                $model->save();
                            }
                            $conn->Close();
                            unlink($upload_path . $fileName);
                            break;
                        default;
                    }
                }
            }
        }

       
    }

    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id),
        ));
    }

    /**
     * Creates a new model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     */
    public function actionCreate() {
        $model = new DAkun;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);



        if (isset($_POST['DAkun'])) {
            $model->attributes = $_POST['DAkun'];
            $as = TSatker::model()->find('KDSATKER=' . $model->KDSATKER);
            $model->KDDEPT = $as->KDDEPT;
            $model->KDUNIT = $as->KDUNIT;
            $model->KDLOKASI = $as->KDLOKASI;
            $model->KDKABKOTA = $as->KDKABKOTA;
            $model->KDKPPN = $as->KDKPPN;
            $ass = TGiat::model()->find('KDGIAT=' . $model->KDGIAT);
            $model->KDPROGRAM = $ass->KDPROGRAM;
            if ($model->save())
                $this->redirect(array('view', 'id' => $model->ID));
        }

        $model2 = new TSatker('search');
        $model2->unsetAttributes();  // clear any default values
        if (isset($_GET['TSatker']))
            $model2->attributes = $_GET['TSatker'];

        $model3 = new TGiat('search');
        $model3->unsetAttributes();  // clear any default values
        if (isset($_GET['TGiat']))
            $model3->attributes = $_GET['TGiat'];

        $model4 = new TOutput('search');
        $model4->unsetAttributes();  // clear any default values
        if (isset($_GET['TOutput']))
            $model4->attributes = $_GET['TOutput'];

        $model5 = new TAkun('search');
        $model5->unsetAttributes();  // clear any default values
        if (isset($_GET['TAkun']))
            $model5->attributes = $_GET['TAkun'];

        $model6 = new TRegister('search');
        $model6->unsetAttributes();  // clear any default values
        if (isset($_GET['TRegister']))
            $model6->attributes = $_GET['TRegister'];

        $this->render('create', array(
            'model' => $model,
            'model2' => $model2,
            'model3' => $model3,
            'model4' => $model4,
            'model5' => $model5,
            'model6' => $model6,
        ));
    }

    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id the ID of the model to be updated
     */
    public function actionUpdate($id) {
        $model = $this->loadModel($id);

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if (isset($_POST['DAkun'])) {
            $model->attributes = $_POST['DAkun'];
            if ($model->save())
                $this->redirect(array('view', 'id' => $model->ID));
        }

        $this->render('update', array(
            'model' => $model,
        ));
    }

    /**
     * Deletes a particular model.
     * If deletion is successful, the browser will be redirected to the 'admin' page.
     * @param integer $id the ID of the model to be deleted
     */
    public function actionDelete($id) {
        if (Yii::app()->request->isPostRequest) {
            // we only allow deletion via POST request
            $this->loadModel($id)->delete();

            // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
            if (!isset($_GET['ajax']))
                $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
        }
        else
            throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
    }

    /**
     * Lists all models.
     */
    public function actionIndex() {
        $dataProvider = new CActiveDataProvider('DAkun');
        $this->render('index', array(
            'dataProvider' => $dataProvider,
        ));
    }

    /**
     * Manages all models.
     */
    public function actionAdmin() {
        $model = new DAkun('search');
        $model->unsetAttributes();  // clear any default values
        if (isset($_GET['DAkun']))
            $model->attributes = $_GET['DAkun'];

        $this->render('admin', array(
            'model' => $model,
        ));
    }

    /**
     * Returns the data model based on the primary key given in the GET variable.
     * If the data model is not found, an HTTP exception will be raised.
     * @param integer the ID of the model to be loaded
     */
    public function loadModel($id) {
        $model = DAkun::model()->findByPk($id);
        if ($model === null)
            throw new CHttpException(404, 'The requested page does not exist.');
        return $model;
    }

    /**
     * Performs the AJAX validation.
     * @param CModel the model to be validated
     */
    protected function performAjaxValidation($model) {
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'dakun-form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
    }

}
